gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\svm\pkdist.m

    function pkdist(data,Alpha,ker,arg,options)
% PKDIST plots kernel distance from a given vector.
% pkdist(data,Alpha,ker,arg,options)
%
% It plots a distance from a point sum( Alpha(i)*Phi(data(:,i)))
% in a feature space induced by a given kernel.
%
% Inputs:
%  data [dim x n] data from the input space describing a vector 
%   in the feture space.
%  Alpha [1 x n] weights of the data.
%  ker [string] kernel identifier; see help kernel.
%  arg [...] kernel argument.
%

% Modifications:
%  13-sep-2002, VF

% set up default options 
if nargin < 5,
   options.background = 0;
   options.patterns = 1;
   options.gridx = 50;
   options.gridy = 50;
   options.psize = 8;
   options.contours = 6;
   options.pstr = 'xk';
else
   if ~isfield(options,'background'), options.background = 0; end
   if ~isfield(options,'patterns'), options.patterns = 1; end
   if ~isfield(options,'gridx'), options.gridx = 25; end
   if ~isfield(options,'gridy'), options.gridy = 25; end
   if ~isfield(options,'psize'), options.psize = 8; end
   if ~isfield(options,'contours'), options.contours = 6; end
   if ~isfield(options,'pstr'), options.pstr = 'xk'; end
end

if options.patterns,
  ppatterns(data,options.pstr,options.psize);
end

%
old_hold = ishold;
hold on;
a = axis;

% limits of current figure
xmin=a(1);
xmax=a(2);
ymin=a(3);
ymax=a(4);
  
% makes grid 
[X,Y] = meshgrid(xmin:(xmax-xmin)/options.gridx:xmax,...
                 ymin:(ymax-ymin)/options.gridy:ymax);

% make testing patterns covering whole grid
tst_data=[reshape(X',1,prod(size(X)));reshape(Y',1,prod(size(Y)))];

% classify points
[dec_fun] = kdist(tst_data,data,Alpha,ker,arg);

% compute color limits
%l=(-min(dec_fun)+max(dec_fun))/2;

% reshape dec_fun
Z = reshape(dec_fun,size(X,1),size(X,2))';

% colors background 
if options.background,
  phandle = pcolor(X,Y,Z);
end

% smooth shading
shading interp;

% plots decision boundary
if options.contours  ~= 0,
  contour(X,Y,Z,options.contours,'k');
end

% set color limits and colormap
if options.background,
  set(phandle, 'LineStyle','none' );
%  set(gca,'Clim',[-l l]);
  set(gca,'Clim',[-min(dec_fun) max(dec_fun)]);
  
  % creates colormap and sets it up
  g=gray(64);
  cmp=g;
%  cmp=[g(33:end,:);flipud(g(33:end,:))];
%  cmp(1:32,1)=cmp(1:32,1)/2;
%  cmp(1:32,3)=cmp(1:32,3)/2;
%  cmp(33:end,3)=cmp(33:end,3)/2;
%  cmp(33:end,2)=cmp(33:end,2)/2;
  colormap(cmp)
end


%
if ~old_hold,
   hold off;
end

return;